/*
 *  Copyright 2019-2023 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.information.rest;

import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BizException;
import me.zhengjie.modules.information.domain.ReserveConsult;
import me.zhengjie.modules.information.service.ReserveConsultService;
import me.zhengjie.modules.information.domain.vo.ReserveConsultQueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
 * @author yiwei.he
 * @date 2024-05-09
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "预约咨询管理")
@RequestMapping("/api/reserveConsult")
@Slf4j
public class ReserveConsultController {

    private final ReserveConsultService reserveConsultService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    public void exportReserveConsult(HttpServletResponse response, ReserveConsultQueryCriteria criteria) throws IOException {
        reserveConsultService.download(reserveConsultService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询预约咨询")
    @ApiOperation("查询预约咨询")
//    @PreAuthorize("@el.check('reserveConsult:list')")
    public ResponseEntity<PageResult<ReserveConsult>> queryReserveConsult(ReserveConsultQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(reserveConsultService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("预约咨询(小程序)")
    @ApiOperation("预约咨询(小程序)")
    public ResponseEntity<Object> createReserveConsult(@Validated @RequestBody ReserveConsult resources){
        return new ResponseEntity<>(reserveConsultService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改预约咨询")
    @ApiOperation("修改预约咨询")
//    @PreAuthorize("@el.check('reserveConsult:edit')")
    public ResponseEntity<Object> updateReserveConsult(@Validated @RequestBody ReserveConsult resources){
        reserveConsultService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

//    @DeleteMapping
//    @Log("删除预约咨询")
//    @ApiOperation("删除预约咨询")
//    @PreAuthorize("@el.check('reserveConsult:del')")
//    public ResponseEntity<Object> deleteReserveConsult(@RequestBody List<Long> ids) {
//        reserveConsultService.deleteAll(ids);
//        return new ResponseEntity<>(HttpStatus.OK);
//    }

    @PostMapping("/list")
    @Log("查询预约咨询(小程序)")
    @ApiOperation("查询预约咨询（小程序）")
    public ResponseEntity<PageResult<ReserveConsult>> consultList(@RequestBody  ReserveConsultQueryCriteria criteria) throws BizException {
        log.info("/api/reserveConsult/list 查询预约咨询:{}",criteria);
        return new ResponseEntity<>(reserveConsultService.consultList(criteria,criteria.getPage()),HttpStatus.OK);
    }

    @PostMapping("/editStatus")
    @Log("已处理（咨询状态-后管使用）")
    @ApiOperation("已处理（咨询状态-后管使用）")
    public ResponseEntity<Boolean> editStatus(@RequestBody  ReserveConsultQueryCriteria criteria) throws BizException {
        return new ResponseEntity<>(reserveConsultService.editStatus(criteria),HttpStatus.OK);
    }

}